package ai.phase.cognition.development;
import ai.filetools.*;
/**
 * The MapBuilder allows one to create template maps easily
 * @author Andrew
 * @version 1.0
 * @updated 08-Jun-2010 7:27:23 PM
 */
public class MapBuilder {

	/**
	 * Arguments are:
	 * (1) The mapFileFullName
	 * (2) Dimensions of map as string, "Length, Width"
	 * (3) DefaultUtilityOfEachInteriorRegion
	 * 
	 * @param args    args
	 */
	
	private static final String j_SpecSeparator="_";
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String mapFileFullName=args[0];
		String dimensionList=args[1];
		String defaultUtility =args[2];
		String errorLogFile="e:\\errors.log";
		int Width,Height;
		String[] dSplit;
		String widthS,heightS;
		StringBuffer lineOutput;
		String desigCode;
		int regionIndex=0;
		
		try
		{
			if (StandardTools.FileExists(mapFileFullName))
				StandardTools.DeleteFile(mapFileFullName);
			dSplit=dimensionList.split(",");
			widthS=dSplit[0];
			heightS=dSplit[1];
			Width=Integer.parseInt(widthS);
			Height=Integer.parseInt(heightS);
			for (int i=0;i<Height;i++)
			{
				lineOutput= new StringBuffer();
				for (int j=0;j<Width;j++)
				{
					desigCode=String.format("%2$s%3$s%1$s", defaultUtility,regionIndex++,j_SpecSeparator);
					if (j==0)
						lineOutput.append(desigCode);
					else
					{
						lineOutput.append(",");
						lineOutput.append(desigCode);
					}
				}
				if (i<(Height-1))
					lineOutput.append("\n");
				StandardTools.AppendAllText(mapFileFullName, lineOutput.toString());
			}
			
		}
		catch (Exception e)
		{
			StandardTools.AppendAllText(errorLogFile, e.toString());
		}
	}
	
	

}
